package com.github.data_manage.controller

import com.github.data_manage.dao.BaseDao
import com.github.data_manage.domain.po.AbstractModifyPo
import com.github.data_manage.domain.po.IHasId
import com.github.data_manage.util.AuthContextHolder
import org.springframework.beans.factory.annotation.Autowired

abstract class BaseController<T> where T : IHasId {

    @Autowired
    protected open lateinit var authContextHolder: AuthContextHolder

    @Autowired
    protected open lateinit var baseDao: BaseDao<T>


    protected fun saveOrUpdateEntity(t: T) {
        if (t.getId() == null) {
            saveEntity(t)
        } else {
            updateEntity(t)
        }
        baseDao.save(t)
    }


    private fun saveEntity(t: T) {
//        val currentUser = authContextHolder.currentUser()
//        t.createBy = currentUser.id
//        t.createUser = currentUser.name
    }

    private fun updateEntity(t: T) {
//        val currentUser = authContextHolder.currentUser()
//        t.updateBy = currentUser.id
//        t.updateUser = currentUser.name
    }

}
